/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jhave.client;

import javax.swing.*;
import java.util.*;
import java.awt.*;
import org.jdom.Element;
/**
 *
 * @author Kevin
 */
public class JHAVE_Combobox_Factory {

    JPanel returnedPanel;
    JPanel comboBoxPanel;
    Vector components;
    GridLayout grid;
    JComboBox combobox;

     /**
     * Finds the correct ComboBox JHAVE_Element and adds it to its proper place in the returnedPanel JPanel and components Vector.
     *
     *@param
     *@param child - Current element.
     *@param returnedPanel - The main JPanel.
     *@param components - Vector that holds added elements.
     *@param grid - Current GridLayout
     *@param combobox -Current JComboBox 
     *@param comboBoxPanel - JPanel that will hold the combobox and it's labels
     *
     *@return JHAVE_Element.
     */
    public JHAVE_Element get_JHAVE_Element(Element child, JPanel returnedPanel, Vector components, GridLayout grid, JComboBox combobox, JPanel comboBoxPanel){
        String type = child.getName();
        JHAVE_Abstract_Combobox_Element element = null;
        this.returnedPanel = returnedPanel;
        this.components = components;
        this.comboBoxPanel = comboBoxPanel;
        this.grid = grid;
        this.combobox = combobox;


        if(type.equalsIgnoreCase("label_line")){
            element = new Combobox_Label_Line_Element(child, this.returnedPanel, this.components, this.grid, this.combobox, this.comboBoxPanel);
	    element.addElementToPanel();
            this.returnedPanel = element.returnPanel();
            this.components = element.returnComponents();
            this.grid = element.returnGrid();
            this.combobox = element.returnComboBox();
            this.comboBoxPanel = element.returnComboBoxPanel();
        }
	else if(type.equalsIgnoreCase("option")){
            element = new Combobox_Option_Element(child, this.returnedPanel, this.components, this.grid, this.combobox, this.comboBoxPanel);
	    element.addElementToPanel();
            this.returnedPanel = element.returnPanel();
            this.components = element.returnComponents();
            this.grid = element.returnGrid();
            this.combobox = element.returnComboBox();
            this.comboBoxPanel = element.returnComboBoxPanel();
	}
        else{
            //Throw error stating not a proper type
        }

        return element;

    }

     /**
     * Returns returnedPanel.
     *
     *@return Returns the main JPanel.
     */
    public JPanel returnPanel(){
        return returnedPanel;
    }
    
     /**
     * Returns ComboBox panel.
     *
     *@return Returns ComboBox panel.
     */
    public JPanel returnComboBoxPanel(){
        return comboBoxPanel;
    }

     /**
     * Returns the components vector.
     *
     *@return Returns the components vector.
     */
    public Vector returnComponents(){
        return components;
    }

     /**
     * Returns GridLayout.
     *
     *@return Returns GridLayout.
     */
    public GridLayout returnGrid(){
        return grid;
    }

     /**
     * Returns combobox.
     *
     *@return Returns combobox JComboBox.
     */
    public JComboBox returnComboBox(){
        return combobox;
    }
}